using UnityEngine;

public class FreeForAll : BaseTask
{
	public static FreeForAll instance;

	private float timecheck;

	private float resettime = 5f;

	private int planenum;

	private int planeatt;

	public override void MyUpdate()
	{
		if (timebegin)
		{
			stoptime += Time.deltaTime;
			if (Mathf.FloorToInt(stoptime) == 1)
			{
				timeone();
			}
			else if (Mathf.FloorToInt(stoptime) == 3)
			{
				timetwo();
			}
			else if (Mathf.FloorToInt(stoptime) == 4)
			{
				timethree();
			}
			if (stoptime >= 4f)
			{
				stoptime = 0f;
				timebegin = false;
			}
		}
		else
		{
			if (FinishState)
			{
				return;
			}
			base.MyUpdate();
			TimeCal -= Time.deltaTime;
			if (TimeCal <= 0f)
			{
				FinishState = true;
				isSuccess = true;
			}
			UIController.instance.show_time(TimeCal);
			timecheck += Time.deltaTime;
			if (timecheck > 1f)
			{
				timecheck = 0f;
				AIPool.instance.aiplane_reset(plane_smothfollow.instance.transform);
			}
			if (plane_smothfollow.instance.isdied)
			{
				UIController.instance.show_hitinfo_down("你将在 " + ((int)resettime + 1) + " 秒后复活");
				resettime -= Time.deltaTime;
				if (resettime <= 0f)
				{
					resettime = 5f;
					plane_smothfollow.instance.Reset_posrot();
					UIController.instance.show_hitinfo_down(string.Empty);
				}
			}
		}
	}

	public override void MyStart()
	{
		base.MyStart();
		if (instance == null)
		{
			instance = this;
		}
		switch (GlobalInf.chanllenge_mode)
		{
			case 0:
				planenum = 5;
				planeatt = DataController.instance.ffadata[0].planeatt;
				break;
			case 1:
				planenum = 7;
				planeatt = DataController.instance.ffadata[1].planeatt;
				break;
			case 2:
				planenum = 9;
				planeatt = DataController.instance.ffadata[2].planeatt;
				break;
		}
		AIPool.instance.creat_plane_fixed(planenum, planeatt, DataController.instance.AIStartPos);
		AIPool.instance.DisableAllAI();
	}

	public override void MyEnd()
	{
		base.MyEnd();
		if (instance != null)
		{
			instance = null;
		}
	}

	public override void timeone()
	{
		base.timeone();
		if (!one)
		{
			one = true;
			UIController.instance.show_hitinfo("所有战斗机都是敌人。准备战斗");
			UIController.instance.hitinfo_appear();
		}
	}

	public override void timetwo()
	{
		base.timetwo();
		if (!two)
		{
			two = true;
		}
	}

	public override void timethree()
	{
		base.timethree();
		if (!three)
		{
			three = true;
			UIController.instance.hitinfo_disappear();
			AIPool.instance.EnableAllAI();
		}
	}

	public override void timefour()
	{
		base.timefour();
		if (!four)
		{
			four = true;
		}
	}
}
